package com.jlanglang.glide.loaderdemo

import android.content.Context
import com.bumptech.glide.Glide
import com.bumptech.glide.Registry
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.module.AppGlideModule
import com.jlanglang.glide.loaderdemo.loader.UrlModel
import com.jlanglang.glide.loaderdemo.loader.UrlModelLoader
import java.io.InputStream

@GlideModule
class GlideModule : AppGlideModule() {
    override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
        super.registerComponents(context, glide, registry)
        //关键代码
        registry.append(
            UrlModel::class.java, InputStream::class.java,
            SimpleModelLoaderFactory(UrlModelLoader::class)
        )
    }

    /**
     * 这里不开启，避免添加相同的modules两次
     * @return
     */
    override fun isManifestParsingEnabled(): Boolean {
        return false
    }
}